import { defineStore } from "pinia";
import { store } from '@/store';

interface conversationType {
  type: string,
  conversationID: string,
  userProfile?: {
      userID: string | number
  },
  groupProfile?: {
      groupID: string | number,
      avatar: string,
      name: string,
      selfInfo: {
          messageRemindType: string,
          role: string,
      }
  }
}
interface timState {
    isLogin: boolean,
    isSDKReady: boolean,
    conversationList: any[],
    messageList: any[],
    conversation: conversationType,
    scrollTop: number,
    userInfo: object,
    unreadTotal: number
}

const createState = (): timState => ({
    isLogin: false,
    isSDKReady: false,
    conversationList: [],
    messageList: [],
    conversation: {
      type: '',
      conversationID: ''
    },
    scrollTop: 0,
    userInfo: {},
    unreadTotal: 0
});


export const useImStore = defineStore({
    id: 'im',
    state: () => createState(),
    getters: {},
    actions: {
      // 设置IM消息会话列表
      setImConversationList(data: any[]){
        this.conversationList = data;
      },
      // 设置当前IM会话窗口对象
      setConversationItem(data: conversationType) {
        this.conversation = data;
      }
    }
})

export function useImStoreWithOut() {
    return useImStore(store);
}